package org.docmanagement.commons.struts;

import java.util.Iterator;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;

/**
 * Created on 16 nov. 2004
 * @author eveno
 */
public class CommonForm extends ActionForm
{
	private static final long serialVersionUID = 1L;

    private Log log = LogFactory.getLog(getClass());

    public CommonForm()
    {
        super();
    }

    @SuppressWarnings("unchecked")
    public String toString()
    {
        try
        {
            Map<String, Object> properties = BeanUtils.describe(this);
            Iterator<Map.Entry<String, Object>> iter = properties.entrySet().iterator();
            ToStringBuilder builder = new ToStringBuilder(this);
            while (iter.hasNext())
            {
                Map.Entry<String, Object> entry = iter.next();
                builder.append(String.valueOf(entry.getKey()), entry.getValue());
            }
            return builder.toString();
        }
        catch (Exception e)
        {
            log.warn("Can't introspect bean", e);
            return "Can't introspect bean";
        }
    }
}
